package com.zyj.test.month1.day1;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Yijia Zhang
 * @create 2024-04-18 23:01
 */
public class code0001 {
    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        int idx = 0;
        for (int num : nums) {
            map.put(num, idx++);
        }
        for (int i = 0; i < nums.length; i++) {
            if (map.containsKey(target - nums[i]) && i != map.get(target - nums[i])) {
                return new int[] {i,  map.get(target - nums[i])};
            }
        }
        return new int[0];
    }
}
